<title>利润计算</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>销售管理</cite></a>
        <a><cite>利润汇总</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">店铺名称</label>
                    <div class="layui-input-inline">
                        <select name="mallId" id="app-mall-list" lay-filter="app-mall-filter">
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="productName" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">sku货号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="skuExtCode" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">skuId</label>
                    <div class="layui-input-inline">
                        <input type="text" name="productSkuId" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list">
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="app-toolbar-syncWarehouse">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData" id="syncBtn">
            <i class="layui-icon layui-icon-refresh layui-anim  layui-anim-loop " id="syncIcon"></i>同步店铺数据
        </button>
        <div class="layui-tab-item">时间</div>
    </div>
</script>
<script>
    layui.use('contlist', layui.factory('contlist')).use(['admin', 'contlist', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form
            , setter = layui.setter
            , router = layui.router;
        admin.req({
            url: '/temu/queryMallList',
            type: 'post',
            done: function (data) {
                // if (data.data == null || data.data.length < 1){
                //     layer.msg('当前无会员店铺，请前往店铺开通');
                //     location.href("/UserMall")
                // }
                $.each(data.data, function (index, item) {
                    $('#app-mall-list').append(new Option(item.mallName, item.mallId));// 下拉菜单里添加元素
                });
                form.render('select', 'app-content-list');

                table.render({
                    elem: '#LAY-app-content-list'
                    , url: '/temu/queryWarehouse'
                    , headers: {'access_token': layui.data(setter.tableName)[setter.request.tokenName]}
                    , where: {mallId: $("#app-mall-list option:selected").val()}
                    , method: 'post'
                    // , height: '600'
                    , height: 'full-240'
                    , lineStyle: 'height: 151px;'
                    // , toolbar: true,
                    , toolbar: '#app-toolbar-syncWarehouse'
                    , defaultToolbar: [
                        'filter',
                        {
                            name: 'exports',
                            onClick: function (obj) {
                                // 获得数据并清除临时字段
                                var data = table.clearCacheKey(obj.data);
                                // 当前示例配置项
                                var options = obj.config;
                                // 弹出面板
                                obj.openPanel({
                                    list: [ // 列表
                                        '<li data-type="xls">导出 XLS 文件</li>'
                                    ].join(''),
                                    done: function (panel, list) { // 操作列表
                                        list.on('click', function () {
                                            var type = $(this).data('type')
                                            if (type === 'csv') {
                                                // 调用内置导出方法
                                                table.exportFile(options.id, null, type);
                                            } else if (type === 'xls') {
                                                table.exportFile(options.id, null, type);
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    ]
                    , cols: [[
                        {
                            field: 'productSkcPicture',
                            rowspan: "2",
                            totalRow: '合计：',
                            fixed: 'left',
                            width: 150,
                            title: '商品',
                            align: 'center',
                            templet: function (d) {
                                return '<img src="' + d.productSkcPicture + '"/>'
                            }
                        }
                        , {field: 'className', rowspan: "2", fixed: 'left', title: 'sku属性', width: 90}
                        , {field: 'skuExtCode', rowspan: "2", fixed: 'left', title: 'sku货号', width: 100}
                        // , {field: 'productSkuId',rowspan:"2",fixed: 'left', title: 'skuId',width:100}
                        , {align: 'center', title: '昨日销售', colspan: 4}
                        , {align: 'center', title: '今日销售', colspan: 4}
                        , {align: 'center', title: '7日销售', colspan: 4}
                        , {align: 'center', title: '30日销售', colspan: 4}
                        , {
                            field: 'supplierPrice',
                            rowspan: "2",
                            title: '申报价格',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            field: 'buyingPrice',
                            rowspan: "2",
                            title: '进货价',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {field: 'totalProfit', rowspan: "2", title: '总利润率', width: 95}
                        , {
                            field: 'warehouseInventoryNum',
                            rowspan: "2",
                            title: '可用库存',
                            width: 90,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            field: 'waitReceiveNum',
                            rowspan: "2",
                            title: '已发货库存',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }, {
                            field: 'huoZhi',
                            rowspan: "2",
                            title: '货值',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                    ], [{
                        sort: true,
                        sort: true,
                        field: 'yesterDaySaleVolume',
                        title: '销量',
                        width: 100,
                        totalRow: function (d) {
                            return d.TOTAL_NUMS
                        }
                    }
                        , {
                            sort: true,
                            field: 'yesterDaySalePrice',
                            title: '销售额',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'yesterDaySaleProfit',
                            title: '利润',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'yesterDaySaleBuyingPrice',
                            title: '本金',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        ,
                        {
                            sort: true,
                            sort: true,
                            field: 'todaySaleVolume',
                            title: '销量',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'todaySalePrice',
                            title: '销售额',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'todaySaleProfit',
                            title: '利润',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'todaySaleBuyingPrice',
                            title: '本金',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }

                        , {
                            sort: true,
                            field: 'lastSevenDaysSaleVolume',
                            title: '销量',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'lastSevenDaysSalePrice',
                            title: '销售额',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'lastSevenDaysSaleProfit',
                            title: '利润',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'lastSevenDaysSaleBuyingPrice',
                            title: '本金',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }

                        , {
                            sort: true,
                            field: 'lastThirtyDaysSaleVolume',
                            title: '销量',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'lastThirtyDaysSalePrice',
                            title: '销售额',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'lastThirtyDaysSaleProfit',
                            title: '利润',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }
                        , {
                            sort: true,
                            field: 'lastThirtyDaysSaleBuyingPrice',
                            title: '本金',
                            width: 100,
                            totalRow: function (d) {
                                return d.TOTAL_NUMS
                            }
                        }

                        // ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
                    ]]
                    , totalRow: true
                    , text: {none: '暂无数据,请同步Temu'}
                });
            }
        });
        form.render(null, 'app-content-list');

        // $('#syncBtn').on('click', function(){
        //     console.log(1)
        //     elem.removeClass('layui-icon-refresh-3');
        //     setTimeout(function(){
        //         elem.addClass('layui-icon-loading');
        //     });
        // });
        table.on('toolbar(LAY-app-content-list)', function (obj) {
            $('#syncBtn').addClass('layui-btn-disabled');
            $('#syncIcon').removeClass('layui-icon-refresh');
            $('#syncIcon').addClass('layui-icon-loading layui-anim-rotate ');
            console.log("可以开始同步了");
            admin.req({
                url: '/temu/syncWarehouse',
                type: 'post',
                data:{mallId: $("#app-mall-list option:selected").val()},
                done: function (data) {
                    layer.msg("店铺数据同步成功，当前已是最新数据");
                    $('#syncBtn').removeClass('layui-btn-disabled');
                    $('#syncIcon').removeClass('layui-icon-loading layui-anim-rotate')
                    $('#syncIcon').addClass('layui-icon-refresh')
                    table.reload('LAY-app-content-list', {
                        where: {mallId: $("#app-mall-list option:selected").val()}
                    });
                }
            });
        });

        form.on('submit(LAY-app-contlist-search)', function (data) {
            table.reload('LAY-app-content-list', {
                where: {
                    mallId: $("#app-mall-list option:selected").val(),
                    skuExtCode: data.field.skuExtCode,
                    productSkuId: data.field.productSkuId,
                    productName: data.field.productName
                }
            });

            // form.render(null, 'app-content-list');
        });
        form.on('select(app-mall-filter)', function (data) {
            table.reload('LAY-app-content-list', {
                where: {mallId: data.value}
            });
        });
    });
</script>
